<?php


namespace app\api\alipay;

class AlipaySdk
{
	public $appId = "";
	public $rsaPrivateKey = "";
	public $alipayrsaPublicKey = "";
	public $notifyUrl = "";
	public $encryptKey = "";
	public function __construct($config)
	{
		$this->appId = \strval($config["appId"]);
		$this->rsaPrivateKey = \strval($config["rsaPrivateKey"]);
		$this->alipayrsaPublicKey = \strval($config["alipayrsaPublicKey"]);
		$this->encryptKey = \strval($config["InterfaceContentEncryptionMethod"]);
	}
	public function setNotifyUrl(string $notifyUrl)
	{
		$this->notifyUrl = $notifyUrl;
		return $this;
	}
	public function instance()
	{
		$options = new \Alipay\EasySDK\Kernel\Config();
		$options->protocol = "https";
		$options->gatewayHost = "openapi.alipay.com";
		$options->signType = "RSA2";
		$options->appId = $this->appId;
		$options->merchantPrivateKey = $this->rsaPrivateKey;
		$options->alipayPublicKey = $this->alipayrsaPublicKey;
		$options->notifyUrl = $this->notifyUrl;
		$options->encryptKey = $this->encryptKey;
		$instance = \Alipay\EasySDK\Kernel\Factory::setOptions($options);
		return $instance;
	}
}